import java.util.Scanner;

/**
 * @author vivi
 * @description
 * @date 2024/4/25
 */
public class demo2 {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int day = scanner.nextInt();

        int ret = 0; // 收益
        int min = scanner.nextInt(); // 假定第一天是收益最低的一天

        int x = 0;
        for (int i = 1; i < day; i++) {
            x = scanner.nextInt();
            // 先更新ret
            ret = Math.max(ret,x-min);
            // 再更新min
            min = Math.min(min,x);
        }
        if(ret < 0){
            System.out.println("0");
        }else {
            System.out.println(ret);
        }

    }
}
